package com.echo.controller;

import com.echo.common.utils.AuthorizationUtil;
import com.echo.entity.bean.CommonResult;
import com.echo.entity.dto.AssessmentDTO;
import com.echo.entity.vo.AssessmentVO;
import com.echo.service.Impl.AssessmentServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author ATSELI
 * @version 1.0
 * @date 2021/7/18 11:32
 */

@RestController
@RequestMapping("/asse")
public class AssessmentController {

    private final AssessmentServiceImpl service;

    public AssessmentController(AssessmentServiceImpl service) {
        this.service = service;
    }

    @PostMapping("/ad")
    public CommonResult<String> add(@RequestBody AssessmentDTO assessmentDTO,
                                    HttpServletRequest request){
        int result = service.add(assessmentDTO, request);
        if (result == 1){
            return new CommonResult<>(20000, "ok", "申请成功");
        }if (result == -1){
            return new CommonResult<>(50001, "error", "申请已提交,请勿重复提交");
        } {
            return new CommonResult<>(50001, "error", "申请已通过,请勿重复申请");
        }
    }

    @GetMapping("/se")
    public CommonResult<AssessmentVO> sel(HttpServletRequest request){
        AssessmentVO assessment = service.select(request);
        if (assessment != null){
            return new CommonResult<AssessmentVO>(20000, "ok", assessment);
        }else {
            return new CommonResult<AssessmentVO>(50002, "error", null);
        }
    }


    // @PostMapping("/test")
    // public boolean test(){
    //     AuthorizationUtil authorizationUtil = new AuthorizationUtil(authorizationDAO, redisUtil);
    //     return authorizationUtil.authorityJudgement(1);
    // }
}
